package ord2.database;

import ord2.core.AbstractQuery;
import ord2.core.Result;

/**
 * Specifies a way to connect with some database. This interface is used to
 * retrieve some data from a database.
 *
 * @author José Ivan
 * @author Edviges
 *
 */
public interface DatabaseConnector {

    /**
     * Does a connection with database
     * @throws Throwable If any problem occurs
     */
    void connect() throws Throwable;
    
    /**
     * Verifies is this connector is connected
     * @return true if is connected false otherwise
     */
    boolean isConnected();
    
    /**
     * Does a query in database.
     * @param query Query that will be used
     * @param <Q> Type of encapsulated object by query
     * @return Array containg results from database
     * @throws Throwable if any error occurs
     * @see AbstractQuery
     * @see Result
     */
    <Q> Result[] query(AbstractQuery<Q> query) throws Throwable ;
    
    /**
     * Disconnects from database
     * @throws Throwable if any problem occurs
     */
    void disconnect() throws Throwable;
}
